<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>订单详情 - 管理后台</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="${pageContext.request.contextPath}/logo/favicon.ico">
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .sidebar {
            min-height: calc(100vh - 56px);
        }
        .table-dark {
            background-color: #212529;
        }
    </style>
</head>
<body>
    <jsp:include page="../common/header.jsp"/>
    
    <div class="container-fluid">
        <div class="row">
            <jsp:include page="../common/sidebar.jsp"/>
            
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
                <div class="pt-3">
                    <h1 class="h2 mb-4">订单详情</h1>
                    
                    <c:if test="${order != null}">
                        <!-- 订单信息 -->
                        <div class="card mb-3">
                            <div class="card-header bg-dark text-white">
                                <h5 class="mb-0">订单信息</h5>
                            </div>
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-6">
                                        <p><strong>订单编号：</strong>${order.orderNo}</p>
                                        <p><strong>下单时间：</strong><fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></p>
                                        <p><strong>订单状态：</strong>
                                            <c:choose>
                                                <c:when test="${order.status == 0}"><span class="badge bg-warning">待付款</span></c:when>
                                                <c:when test="${order.status == 1}"><span class="badge bg-info">待发货</span></c:when>
                                                <c:when test="${order.status == 2}"><span class="badge bg-primary">待收货</span></c:when>
                                                <c:when test="${order.status == 3}"><span class="badge bg-success">已完成</span></c:when>
                                                <c:when test="${order.status == 4}"><span class="badge bg-danger">已取消</span></c:when>
                                                <c:when test="${order.status == 5}"><span class="badge bg-secondary">售后中</span></c:when>
                                            </c:choose>
                                        </p>
                                        <p><strong>用户ID：</strong>${order.userId}</p>
                                        <p><strong>商户ID：</strong>${order.merchantId}</p>
                                        <c:if test="${order.paymentMethod != null}">
                                            <p><strong>支付方式：</strong>${order.paymentMethod}</p>
                                        </c:if>
                                        <c:if test="${order.paymentTime != null}">
                                            <p><strong>支付时间：</strong><fmt:formatDate value="${order.paymentTime}" pattern="yyyy-MM-dd HH:mm:ss"/></p>
                                        </c:if>
                                    </div>
                                    <div class="col-md-6">
                                        <p><strong>收货人：</strong>${order.receiverName}</p>
                                        <p><strong>联系电话：</strong>${order.receiverPhone}</p>
                                        <p><strong>收货地址：</strong>${order.deliveryAddress}</p>
                                        <c:if test="${order.logisticsCompany != null}">
                                            <p><strong>物流公司：</strong>${order.logisticsCompany}</p>
                                            <p><strong>物流单号：</strong>${order.logisticsNo}</p>
                                        </c:if>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 商品明细 -->
                        <div class="card mb-3">
                            <div class="card-header bg-dark text-white">
                                <h5 class="mb-0">商品明细</h5>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-hover">
                                        <thead class="table-dark">
                                            <tr>
                                                <th>商品名称</th>
                                                <th>单价</th>
                                                <th>数量</th>
                                                <th>小计</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <c:forEach var="item" items="${order.orderItems}">
                                                <tr>
                                                    <td>${item.productName}</td>
                                                    <td>¥<fmt:formatNumber value="${item.price}" pattern="#,##0.00"/></td>
                                                    <td>${item.quantity}</td>
                                                    <td>¥<fmt:formatNumber value="${item.subtotal}" pattern="#,##0.00"/></td>
                                                </tr>
                                            </c:forEach>
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <td colspan="3" class="text-end"><strong>订单总额：</strong></td>
                                                <td><strong class="text-danger">¥<fmt:formatNumber value="${order.totalAmount}" pattern="#,##0.00"/></strong></td>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                        
                        <div class="text-center">
                            <a href="${pageContext.request.contextPath}/admin/order" class="btn btn-secondary">返回订单列表</a>
                        </div>
                    </c:if>
                    
                    <c:if test="${order == null}">
                        <div class="alert alert-danger">订单不存在</div>
                        <a href="${pageContext.request.contextPath}/admin/order" class="btn btn-secondary">返回订单列表</a>
                    </c:if>
                </div>
            </main>
        </div>
    </div>
    
    <script src="${pageContext.request.contextPath}/js/bootstrap.bundle.min.js"></script>
</body>
</html>

